<?php
define('FSQL_TYPE_UNSPECIFIED', 1);
define('FSQL_DB_UNSPECIFIED', 2);
define('FSQL_DB_NOT_EXIST', 3);
define('FSQL_TYPE_UNKNOWN', 4);

class fauxSQL
{
  private $create_table;
  private $select;
  private $update;
  private $insert;
  private $replace;
  private $delete;
  private $truncate;
  private $errno;

  public function __construct()
  {
    $this->create_table = null;
    $this->select = null;
    $this->update = null;
    $this->insert = null;
    $this->replace = null;
    $this->delete = null;
    $this->truncate = null;
    $this->errno = array();
  }

  public function query($db_query)
  {
    # The type of query, so we can pass the data off to the right handler.
    if(empty($db_query['type']))
    {
      # Gotta have that query type.
      $this->errno[] = FSQL_TYPE_UNSPECIFIED;
      return false;
    }
    # A fauxSQL database is really just a folder :P We need it though!
    elseif(empty($db_query['db']) || !file_exists($db_query['db']) || !is_dir($db_query['db']))
    {
      $this->errno[] = empty($db_query['db']) ? FSQL_DB_UNSPECIFIED : FSQL_DB_NOT_EXIST;
      return false;
    }

    $db_query['type'] = strtoupper($db_query['type']);

    $obj = null;
    switch($db_query['type'])
    {
      case 'CREATE TABLE':

        if(empty($this->create_table))
        {
          require_once(dirname(__FILE__). '/CreateTable_fauxSQL.class.php');
          $this->create_table = new CreateTable_fauxSQL;
        }

        $obj = $this->create_table;

        break;

      case 'SELECT':

        break;

      case 'UPDATE':

        break;

      case 'INSERT':

        break;

      case 'REPLACE':

        break;

      case 'DELETE':

        break;

      case 'TRUNCATE':

        break;

      default:
        # Unknown query type.
        $this->errno[] = FSQL_TYPE_UNKNOWN;
        return false;
    }

    # Let the individual class handle it.
    $return = $obj->query($db_query);

    if(is_int($return))
    {
      $this->errnop[] = $return;
      return false;
    }
    else
      return $return;
  }
}
?>